<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="企业名称" prop="organizationName">
        <el-input
          v-model="queryParams.organizationName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统一社会信用代码" prop="organizationCode">
        <el-input
          v-model="queryParams.organizationCode"
          placeholder="请输入统一社会信用代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工商营业执照注册号" prop="licenseNum">
        <el-input
          v-model="queryParams.licenseNum"
          placeholder="请输入工商营业执照注册号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item
        label="注册所在省(自治区、直辖市)(字典表：SYS_AREA)"
        prop="provinceNum"
      >
        <el-input
          v-model="queryParams.provinceNum"
          placeholder="请输入注册所在省(自治区、直辖市)(字典表：SYS_AREA)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item
        label="注册所在地(市、州、盟)(字典表：SYS_AREA)"
        prop="cityNum"
      >
        <el-input
          v-model="queryParams.cityNum"
          placeholder="请输入注册所在地(市、州、盟)(字典表：SYS_AREA)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item
        label="注册所在县(区、市、旗)(字典表：SYS_AREA)"
        prop="countyNum"
      >
        <el-input
          v-model="queryParams.countyNum"
          placeholder="请输入注册所在县(区、市、旗)(字典表：SYS_AREA)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业营业地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入企业营业地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业营业地址邮政编码" prop="postalCode">
        <el-input
          v-model="queryParams.postalCode"
          placeholder="请输入企业营业地址邮政编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法定代表人姓名" prop="legalMan">
        <el-input
          v-model="queryParams.legalMan"
          placeholder="请输入法定代表人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法定代表人证件号码" prop="legalManIdcard">
        <el-input
          v-model="queryParams.legalManIdcard"
          placeholder="请输入法定代表人证件号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法定代表人职务" prop="legalManDuty">
        <el-input
          v-model="queryParams.legalManDuty"
          placeholder="请输入法定代表人职务"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法定代表人职称" prop="legalManProtitle">
        <el-input
          v-model="queryParams.legalManProtitle"
          placeholder="请输入法定代表人职称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item
        label="企业登记注册类型(字典表：TBECONTYPEDIC)"
        prop="economicNum"
      >
        <el-input
          v-model="queryParams.economicNum"
          placeholder="请输入企业登记注册类型(字典表：TBECONTYPEDIC)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="注册资本(万元)" prop="regprin">
        <el-input
          v-model="queryParams.regprin"
          placeholder="请输入注册资本(万元)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实收资金(万元)" prop="factRegprin">
        <el-input
          v-model="queryParams.factRegprin"
          placeholder="请输入实收资金(万元)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成立日期" prop="corpbirthDate">
        <el-date-picker
          clearable
          v-model="queryParams.corpbirthDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择成立日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="办公电话" prop="officePhone">
        <el-input
          v-model="queryParams.officePhone"
          placeholder="请输入办公电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="传真号码" prop="fax">
        <el-input
          v-model="queryParams.fax"
          placeholder="请输入传真号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人姓名" prop="linkMan">
        <el-input
          v-model="queryParams.linkMan"
          placeholder="请输入联系人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人办公电话" prop="linkTel">
        <el-input
          v-model="queryParams.linkTel"
          placeholder="请输入联系人办公电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人手机号码" prop="linkPhone">
        <el-input
          v-model="queryParams.linkPhone"
          placeholder="请输入联系人手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入联系邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业网址" prop="url">
        <el-input
          v-model="queryParams.url"
          placeholder="请输入企业网址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据来源系统" prop="dataSource">
        <el-input
          v-model="queryParams.dataSource"
          placeholder="请输入数据来源系统"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业净资产" prop="assets">
        <el-input
          v-model="queryParams.assets"
          placeholder="请输入企业净资产"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否外商投资 0:是；1：否" prop="checkForeign">
        <el-input
          v-model="queryParams.checkForeign"
          placeholder="请输入是否外商投资 0:是；1：否"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经营范围" prop="businesssCope">
        <el-input
          v-model="queryParams.businesssCope"
          placeholder="请输入经营范围"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否承诺" prop="isCommitment">
        <el-input
          v-model="queryParams.isCommitment"
          placeholder="请输入是否承诺"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除标志" prop="deleteFlag">
        <el-input
          v-model="queryParams.deleteFlag"
          placeholder="请输入删除标志"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['crane:company:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['crane:company:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['crane:company:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['crane:company:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="companyList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column
        label="企业名称"
        align="center"
        prop="organizationName"
      />
      <el-table-column
        label="统一社会信用代码"
        align="center"
        prop="organizationCode"
      />
      <el-table-column
        label="工商营业执照注册号"
        align="center"
        prop="licenseNum"
      />
      <el-table-column
        label="注册所在省(自治区、直辖市)(字典表：SYS_AREA)"
        align="center"
        prop="provinceNum"
      />
      <el-table-column
        label="注册所在地(市、州、盟)(字典表：SYS_AREA)"
        align="center"
        prop="cityNum"
      />
      <el-table-column
        label="注册所在县(区、市、旗)(字典表：SYS_AREA)"
        align="center"
        prop="countyNum"
      />
      <el-table-column label="企业营业地址" align="center" prop="address" />
      <el-table-column
        label="企业营业地址邮政编码"
        align="center"
        prop="postalCode"
      />
      <el-table-column label="法定代表人姓名" align="center" prop="legalMan" />
      <el-table-column
        label="法定代表人证件号码"
        align="center"
        prop="legalManIdcard"
      />
      <el-table-column
        label="法定代表人职务"
        align="center"
        prop="legalManDuty"
      />
      <el-table-column
        label="法定代表人职称"
        align="center"
        prop="legalManProtitle"
      />
      <el-table-column
        label="企业登记注册类型(字典表：TBECONTYPEDIC)"
        align="center"
        prop="economicNum"
      />
      <el-table-column label="注册资本(万元)" align="center" prop="regprin" />
      <el-table-column
        label="实收资金(万元)"
        align="center"
        prop="factRegprin"
      />
      <el-table-column
        label="成立日期"
        align="center"
        prop="corpbirthDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.corpbirthDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="办公电话" align="center" prop="officePhone" />
      <el-table-column label="传真号码" align="center" prop="fax" />
      <el-table-column label="联系人姓名" align="center" prop="linkMan" />
      <el-table-column label="联系人办公电话" align="center" prop="linkTel" />
      <el-table-column label="联系人手机号码" align="center" prop="linkPhone" />
      <el-table-column label="联系邮箱" align="center" prop="email" />
      <el-table-column label="企业网址" align="center" prop="url" />
      <el-table-column label="数据来源系统" align="center" prop="dataSource" />
      <el-table-column label="企业净资产" align="center" prop="assets" />
      <el-table-column
        label="是否外商投资 0:是；1：否"
        align="center"
        prop="checkForeign"
      />
      <el-table-column
        label="企业类型 1：建设单位 2：勘察 4：施工 5：监理 10：劳务分包 11：专业分包"
        align="center"
        prop="enterpriseType"
      />
      <el-table-column label="经营范围" align="center" prop="businesssCope" />
      <el-table-column label="是否承诺" align="center" prop="isCommitment" />
      <el-table-column label="删除标志" align="center" prop="deleteFlag" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['crane:company:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['crane:company:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="企业名称" prop="organizationName">
          <el-input
            v-model="form.organizationName"
            placeholder="请输入企业名称"
          />
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="organizationCode">
          <el-input
            v-model="form.organizationCode"
            placeholder="请输入统一社会信用代码"
          />
        </el-form-item>
        <el-form-item label="工商营业执照注册号" prop="licenseNum">
          <el-input
            v-model="form.licenseNum"
            placeholder="请输入工商营业执照注册号"
          />
        </el-form-item>
        <el-form-item
          label="注册所在省(自治区、直辖市)(字典表：SYS_AREA)"
          prop="provinceNum"
        >
          <el-input
            v-model="form.provinceNum"
            placeholder="请输入注册所在省(自治区、直辖市)(字典表：SYS_AREA)"
          />
        </el-form-item>
        <el-form-item
          label="注册所在地(市、州、盟)(字典表：SYS_AREA)"
          prop="cityNum"
        >
          <el-input
            v-model="form.cityNum"
            placeholder="请输入注册所在地(市、州、盟)(字典表：SYS_AREA)"
          />
        </el-form-item>
        <el-form-item
          label="注册所在县(区、市、旗)(字典表：SYS_AREA)"
          prop="countyNum"
        >
          <el-input
            v-model="form.countyNum"
            placeholder="请输入注册所在县(区、市、旗)(字典表：SYS_AREA)"
          />
        </el-form-item>
        <el-form-item label="企业营业地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入企业营业地址" />
        </el-form-item>
        <el-form-item label="企业营业地址邮政编码" prop="postalCode">
          <el-input
            v-model="form.postalCode"
            placeholder="请输入企业营业地址邮政编码"
          />
        </el-form-item>
        <el-form-item label="法定代表人姓名" prop="legalMan">
          <el-input
            v-model="form.legalMan"
            placeholder="请输入法定代表人姓名"
          />
        </el-form-item>
        <el-form-item label="法定代表人证件号码" prop="legalManIdcard">
          <el-input
            v-model="form.legalManIdcard"
            placeholder="请输入法定代表人证件号码"
          />
        </el-form-item>
        <el-form-item label="法定代表人职务" prop="legalManDuty">
          <el-input
            v-model="form.legalManDuty"
            placeholder="请输入法定代表人职务"
          />
        </el-form-item>
        <el-form-item label="法定代表人职称" prop="legalManProtitle">
          <el-input
            v-model="form.legalManProtitle"
            placeholder="请输入法定代表人职称"
          />
        </el-form-item>
        <el-form-item
          label="企业登记注册类型(字典表：TBECONTYPEDIC)"
          prop="economicNum"
        >
          <el-input
            v-model="form.economicNum"
            placeholder="请输入企业登记注册类型(字典表：TBECONTYPEDIC)"
          />
        </el-form-item>
        <el-form-item label="注册资本(万元)" prop="regprin">
          <el-input v-model="form.regprin" placeholder="请输入注册资本(万元)" />
        </el-form-item>
        <el-form-item label="实收资金(万元)" prop="factRegprin">
          <el-input
            v-model="form.factRegprin"
            placeholder="请输入实收资金(万元)"
          />
        </el-form-item>
        <el-form-item label="成立日期" prop="corpbirthDate">
          <el-date-picker
            clearable
            v-model="form.corpbirthDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择成立日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="办公电话" prop="officePhone">
          <el-input v-model="form.officePhone" placeholder="请输入办公电话" />
        </el-form-item>
        <el-form-item label="传真号码" prop="fax">
          <el-input v-model="form.fax" placeholder="请输入传真号码" />
        </el-form-item>
        <el-form-item label="联系人姓名" prop="linkMan">
          <el-input v-model="form.linkMan" placeholder="请输入联系人姓名" />
        </el-form-item>
        <el-form-item label="联系人办公电话" prop="linkTel">
          <el-input v-model="form.linkTel" placeholder="请输入联系人办公电话" />
        </el-form-item>
        <el-form-item label="联系人手机号码" prop="linkPhone">
          <el-input
            v-model="form.linkPhone"
            placeholder="请输入联系人手机号码"
          />
        </el-form-item>
        <el-form-item label="联系邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入联系邮箱" />
        </el-form-item>
        <el-form-item label="企业网址" prop="url">
          <el-input v-model="form.url" placeholder="请输入企业网址" />
        </el-form-item>
        <el-form-item label="数据来源系统" prop="dataSource">
          <el-input
            v-model="form.dataSource"
            placeholder="请输入数据来源系统"
          />
        </el-form-item>
        <el-form-item label="企业净资产" prop="assets">
          <el-input v-model="form.assets" placeholder="请输入企业净资产" />
        </el-form-item>
        <el-form-item label="是否外商投资 0:是；1：否" prop="checkForeign">
          <el-input
            v-model="form.checkForeign"
            placeholder="请输入是否外商投资 0:是；1：否"
          />
        </el-form-item>
        <el-form-item label="经营范围" prop="businesssCope">
          <el-input v-model="form.businesssCope" placeholder="请输入经营范围" />
        </el-form-item>
        <el-form-item label="是否承诺" prop="isCommitment">
          <el-input v-model="form.isCommitment" placeholder="请输入是否承诺" />
        </el-form-item>
        <el-form-item label="删除标志" prop="deleteFlag">
          <el-input v-model="form.deleteFlag" placeholder="请输入删除标志" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCompany,
  getCompany,
  delCompany,
  addCompany,
  updateCompany,
} from "@/api/hades/organization/company";

export default {
  name: "Company",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目信息表格数据
      companyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        organizationName: null,
        organizationCode: null,
        licenseNum: null,
        provinceNum: null,
        cityNum: null,
        countyNum: null,
        address: null,
        postalCode: null,
        legalMan: null,
        legalManIdcard: null,
        legalManDuty: null,
        legalManProtitle: null,
        economicNum: null,
        regprin: null,
        factRegprin: null,
        corpbirthDate: null,
        officePhone: null,
        fax: null,
        linkMan: null,
        linkTel: null,
        linkPhone: null,
        email: null,
        url: null,
        dataSource: null,
        assets: null,
        checkForeign: null,
        enterpriseType: null,
        businesssCope: null,
        isCommitment: null,
        deleteFlag: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询项目信息列表 */
    getList() {
      this.loading = true;
      listCompany(this.queryParams).then((response) => {
        this.companyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        organizationName: null,
        organizationCode: null,
        licenseNum: null,
        provinceNum: null,
        cityNum: null,
        countyNum: null,
        address: null,
        postalCode: null,
        legalMan: null,
        legalManIdcard: null,
        legalManDuty: null,
        legalManProtitle: null,
        economicNum: null,
        regprin: null,
        factRegprin: null,
        corpbirthDate: null,
        officePhone: null,
        fax: null,
        linkMan: null,
        linkTel: null,
        linkPhone: null,
        email: null,
        url: null,
        dataSource: null,
        assets: null,
        checkForeign: null,
        enterpriseType: null,
        businesssCope: null,
        isCommitment: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        deleteFlag: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getCompany(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改项目信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateCompany(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCompany(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除项目信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delCompany(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "crane/company/export",
        {
          ...this.queryParams,
        },
        `company_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
